'use strict';
var express = require('express');
var router = express.Router();
var articleModule = require('../../modules/articles_module');


router.post('/:id', function(req, res, next){
  articleModule.addArticle(req.body)
  .then(function(data){
    res.json({
      code: 0,
      message: 'success',
      data: data
    });
  },function(error){
    res.json({
      message: error.message,
    });
  });
});


router.get('/:id', function(req, res, next){
  articleModule.getArticle(req.params.id)
  .then(function(data){
    res.json({
      code: 0,
      message: 'success',
      data: data
    });
  },function(error){
    res.json({
      message: error.message
    });
  });
});


router.put('/:id', function(req, res, next){
  articleModule.updateArticle(req.params.id, req.body)
  .then(function(data){
    res.json({
      code: 0,
      message: 'success',
      data: data
    });
  },function(error){
    res.json({
      message: error.message
    });
  });
});


router.delete('/:id', function(req, res, next){
  articleModule.deleteArticle(req.params.id)
  .then(function(success){
    res.json({
      code: 0,
      message: 'success',
    });
  }, function(error){
    res.json({
      message: error.message
    });
  });
});

module.exports = router;